// pages/account/points.js
var server = require('../../../utils/server');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentData: 0,
    type: ['all','recharge','points'],//recharge充值明细 points积分记录明细 all所有
    limit:10,
    page:1,
    list:'',
    count:0,
    radio:0,
    pagestatus:false,
  },

  //选项卡
  //获取当前滑块的index
  bindchange: function (e) { const that = this; that.setData({ currentData: e.detail.current }) },
  //点击切换，滑块index赋值
  checkCurrent: function (e) {
    const that = this;
    console.log(e)
    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {
      that.setData({ currentData: e.target.dataset.current });
    }
    that.setData({
      radio:e.currentTarget.dataset.current,
      page:1,
    })
    var type = that.data.type;

    that.list(type[e.currentTarget.dataset.current]);
    // this.select(e.target.dataset.current)
  },

  select: function (e = 0) {
    var query = wx.createSelectorQuery();
    //选择id
    var that = this;
    if (e == 0) {
      query.select('.one1').boundingClientRect(function (rect) {
        console.log(rect.height)
        that.setData({
          height: rect.height + 'px'
        })
      }).exec();
    } else if (e == 1) {
      query.select('.two1').boundingClientRect(function (rect) {
        console.log(rect.height)
        that.setData({
          height: rect.height + 'px'
        })
      }).exec();
    } else if (e == 2) {
      query.select('.three1').boundingClientRect(function (rect) {
        console.log(rect.height)
        that.setData({
          height: rect.height + 'px'
        })
      }).exec();
    } else {
      return false;
    }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.select(0);
    var that = this;
    var type = that.data.type;
    that.list(type[0]);

  },

list:function(type){
  var that = this;
  var userinfo = app.globalData.userInfo;
  server.postJSON("/User/point", { type: type, page: that.data.page, limit: that.data.limit, userid: userinfo.user_id }, function (res) {
    console.log(res)
    that.setData({
      list: res.data.log,
      count: res.data.count,
      pagestatus:true,
    })

  });
},

listpage:function(type){
  var that = this;
  var userinfo = app.globalData.userInfo;
  server.postJSON("/User/point", { type: type, page: that.data.page, limit: that.data.limit, userid: userinfo.user_id }, function (res) {
    if(res.data.status == 1){
      var list = that.data.list;
      for (var i = 0; i < res.data.log.length; i++) {
        list.push(res.data.log[i])
      }
      // list = Object.assign(list,res.data.log);
      that.setData({
        list:list,
        pagestatus:true,
      })
      console.log(list)
    }
  });
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(!this.data.pagestatus){
      return;
    }
    var page = this.data.page;
    var count = this.data.count;
    var limit = this.data.limit;
    var limitpage = Math.ceil(count/limit);
    if(page == limitpage){
      wx.showLoading({
        title: '数据加载完毕',
      })
      setTimeout(function(){
        wx.hideLoading();
      },2000)
      return;
    }
    this.setData({
      pagestatus: false,
    })
    page++;
    this.setData({
      page:page,
    })
    var type = this.data.type;
    var radio = this.data.radio;
    this.listpage(type[radio]);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})